// import com.alibaba.druid.DbType;
// import com.alibaba.druid.sql.ast.SQLExpr;
// import com.alibaba.druid.sql.ast.SQLName_ptr;
// import com.alibaba.druid.sql.ast.SQLObject;
// import com.alibaba.druid.sql.ast.SQLStatementImpl;
// import com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr_ptr;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

// import java.util.ArrayList;
// import java.util.List;

#include "SQLCallStatement.h"
#include "../../visitor/SQLASTVisitor.h"
#include "../../../utils/listTran.h"
#include "../expr/SQLVariantRefExpr.h"
#include "../SQLName.h"

SQLCallStatement::SQLCallStatement()
{
  parameters = std::make_shared<std::list<SQLExpr_ptr>>();
}

SQLCallStatement::SQLCallStatement(DbType_ptr dbType)
    : SQLStatementImpl(dbType)
{

  parameters = std::make_shared<std::list<SQLExpr_ptr>>();
}

SQLVariantRefExpr_ptr SQLCallStatement::getOutParameter()
{
  return outParameter;
}

void SQLCallStatement::setOutParameter(SQLVariantRefExpr_ptr outParameter)
{
  this->outParameter = outParameter;
}

SQLName_ptr SQLCallStatement::getProcedureName()
{
  return procedureName;
}

void SQLCallStatement::setProcedureName(SQLName_ptr procedureName)
{
  this->procedureName = procedureName;
}

SQLExpr_list_ptr SQLCallStatement::getParameters()
{
  return parameters;
}

BOOL_ptr SQLCallStatement::isBrace()
{
  return brace;
}

void SQLCallStatement::setBrace(BOOL_ptr brace)
{
  this->brace = brace;
}

void SQLCallStatement::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLCallStatement)))
  {
    acceptChild(visitor, this->outParameter);
    acceptChild(visitor, this->procedureName);
    SQLObject_list_ptr tmp = ListTran::tran_class<SQLExpr, SQLObject>(this->parameters);
    acceptChild(visitor, tmp);
  }
  visitor->endVisit(SharedObject(SQLCallStatement));
}

// @Override
SQLObject_list_ptr SQLCallStatement::getChildren()
{
  SQLObject_list_ptr children = std::make_shared<std::list<SQLObject_ptr>>();
  children->push_back(outParameter);
  children->push_back(procedureName);
  // children.addAll(parameters);
  for (auto it : *parameters)
  {
    children->push_back(it);
  }
  return nullptr;
}
